<?php
/**
 * 修改保留价  初始化数据用 请勿做他用,擅自执行
 * Created by PhpStorm.
 * User: angl
 * Date: 15/12/23
 * Time: 上午9:27
 */
die("The end");
date_default_timezone_set ( "Asia/Shanghai" );
set_time_limit(0);
if (isset($_SERVER ['REQUEST_URI'])) {
    die('error');
}
if (!defined('INC_ROOT_PATH')) {
    define('INC_ROOT_PATH', dirname(dirname(__FILE__)) . '/');
}
require_once (INC_ROOT_PATH . '/inc/Config.php');
require_once (INC_ROOT_PATH . '/inc/MysqliDb.php');

$db = new MysqliDb (MYSQLDB, MYSQLDB_USER, MYSQLDB_PWD, MYSQLDB_DATABASE);
$db->setPrefix ('au_');

$redis = new Redis();
$redis->connect(REDIS_HOST, REDIS_PORT);
$redis->select(4);
//
/* 变速箱类型 */
$GEARBOX = array(
    '1' => '手动',//手动变速箱(MT)
    '2' => '自动',//自动变速箱(AT)
    '3' => '手自一体',//机械式自动变速箱(AMT)
    '4' => 'CVT',//无级变速箱(CVT)
    '5' => '双离合'//双离合变速箱(DCT)
);

echo "----------------------Start-------------------------\n";

//获取已上拍的拍单
$orders = $db->where('bidding_start_time','2016-12-27%','like')->get ("order",null,'order_id,car_id,order_no,bidding_start_time,bid_start_price');
echo "共计".$db->count."个拍单需要补生redis\n";
if ($db->count > 0){
    foreach ($orders as $order) {
        //获取保留价
        $car_detail = $db->where('car_id',$order['car_id'])->getOne('cars','location_area,series_id,car_cc,turbo,gearbox');
        //所在地
        $city = $db->where('city_code',$car_detail['location_area'])->getOne('addr_area','city_name');

        //车系
        $series = $db->where('series_id',$car_detail['series_id'])->getOne('car_series','name');
        //合成车型
        $car_model = '['.$city['city_name'].'] '.$series['name'] . ' ' . $car_detail['car_cc'] . ($car_detail['turbo'] ? 'T' : 'L') . ' ' . $GEARBOX[$car_detail['gearbox']];

        $order_info = array(
            'order_id'=>intval($order['order_id']),
            'bidding_start_time'=>$order['bidding_start_time'],
            'bid_start_price'=>floatval($order['bid_start_price']),
            'order_no'=>$order['order_no'],
            'car_model'=>$car_model
        );
        $k = 'autobidding_order_info_'.$order['order_id'];
        if(!$redis->exists($k)){
            $redis->set($k,json_encode($order_info));
        }
        echo "\n";
        print_r($redis->get($k));
        echo "\n";
    }
}
echo "\n所有键\n";
print_r($redis->keys('*'));
echo "-------------------End-------------------\n";
